/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uy.edu.ort.publicarNoticia;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.EJB;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

/**
 *
 * @author Usuario
 */
@MessageDriven(mappedName = "jms/QueuePublicarNoticia", activationConfig = {
    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
})
public class PublicNoticiaMDB implements MessageListener {
    
       @EJB
    PublicNoticiaSBLocal noticiaSBLocal;
    public PublicNoticiaMDB() {
    }
    
    @Override
    public void onMessage(Message message) {
        try {
        //Verifico el tipo de mensaje
            if (message instanceof TextMessage) {
                TextMessage textMessage = (TextMessage) message;
                //Asigno el procesamiento del mensaje
                noticiaSBLocal.publicarNoticia(textMessage.getText());
                //System.out.println("llego mensaje, " + message);
            }
        } catch (JMSException ex) {
            //System.out.println("Catch de ValidarNoticiaMDB" + ex.getMessage().toString());
            Logger.getLogger(PublicNoticiaMDB.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
